



<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#FFF">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon.png">

<link rel="icon" type="image/ico" sizes="32x32" href="/blog/images/favicon.ico">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">


<link rel="alternate" type="application/rss+xml" title="Endless" href="http://fairy77.gitee.io/rss.xml" />
<link rel="alternate" type="application/atom+xml" title="Endless" href="http://fairy77.gitee.io/atom.xml" />
<link rel="alternate" type="application/json" title="Endless" href="http://fairy77.gitee.io/feed.json" />

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Mulish:300,300italic,400,400italic,700,700italic%7CFredericka%20the%20Great:300,300italic,400,400italic,700,700italic%7CNoto%20Serif%20JP:300,300italic,400,400italic,700,700italic%7CNoto%20Serif%20SC:300,300italic,400,400italic,700,700italic%7CInconsolata:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">

<link rel="stylesheet" href="/blog/css/app.css?v=0.2.5">

  
  <meta name="keywords" content="Linux" />


<link rel="canonical" href="http://fairy77.gitee.io/2020/03/01/linux-basic-operation/">



  <title>
Linux 基本操作 |
夏季大三角 = Endless</title>
<meta name="generator" content="Hexo 5.4.0"></head>
<body itemscope itemtype="http://schema.org/WebPage">
  <div id="loading">
    <div class="cat">
      <div class="body"></div>
      <div class="head">
        <div class="face"></div>
      </div>
      <div class="foot">
        <div class="tummy-end"></div>
        <div class="bottom"></div>
        <div class="legs left"></div>
        <div class="legs right"></div>
      </div>
      <div class="paw">
        <div class="hands left"></div>
        <div class="hands right"></div>
      </div>
    </div>
  </div>
  <div id="container">
    <header id="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="inner">
        <div id="brand">
          <div class="pjax">
          
  <h1 itemprop="name headline">Linux 基本操作
  </h1>
  
<div class="meta">
  <span class="item" title="创建时间：2020-03-01 16:33:32">
    <span class="icon">
      <i class="ic i-calendar"></i>
    </span>
    <span class="text">发表于</span>
    <time itemprop="dateCreated datePublished" datetime="2020-03-01T16:33:32+08:00">2020-03-01</time>
  </span>
  <span class="item" title="本文字数">
    <span class="icon">
      <i class="ic i-pen"></i>
    </span>
    <span class="text">本文字数</span>
    <span>5.5k</span>
    <span class="text">字</span>
  </span>
  <span class="item" title="阅读时长">
    <span class="icon">
      <i class="ic i-clock"></i>
    </span>
    <span class="text">阅读时长</span>
    <span>5 分钟</span>
  </span>
</div>


          </div>
        </div>
        <nav id="nav">
  <div class="inner">
    <div class="toggle">
      <div class="lines" aria-label="切换导航栏">
        <span class="line"></span>
        <span class="line"></span>
        <span class="line"></span>
      </div>
    </div>
    <ul class="menu">
      <li class="item title"><a href="/blog/" rel="start">夏季大三角</a></li>
    </ul>
    <ul class="right">
      <li class="item theme">
        <i class="ic i-sun"></i>
      </li>
      <li class="item search">
        <i class="ic i-search"></i>
      </li>
    </ul>
  </div>
</nav>

      </div>
      <div id="imgs" class="pjax">
        <ul>
          <li class="item" data-background-image="https://tva1.sinaimg.cn/large/6833939bly1giclxp31goj20zk0m8qv5.jpg"></li>
          <li class="item" data-background-image="https://tva1.sinaimg.cn/large/6833939bly1giclh3brzpj20zk0m8ann.jpg"></li>
          <li class="item" data-background-image="https://tva1.sinaimg.cn/large/6833939bly1gipetv6p75j20zk0m8x6p.jpg"></li>
          <li class="item" data-background-image="https://tva1.sinaimg.cn/large/6833939bly1giclx6phq6j20zk0m8e36.jpg"></li>
          <li class="item" data-background-image="https://tva1.sinaimg.cn/large/6833939bly1gipewkhf1zj20zk0m81kx.jpg"></li>
          <li class="item" data-background-image="https://tva1.sinaimg.cn/large/6833939bly1gicis3attqj20zk0m8k7l.jpg"></li>
        </ul>
      </div>
    </header>
    <div id="waves">
      <svg class="waves" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto">
        <defs>
          <path id="gentle-wave" d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z" />
        </defs>
        <g class="parallax">
          <use xlink:href="#gentle-wave" x="48" y="0" />
          <use xlink:href="#gentle-wave" x="48" y="3" />
          <use xlink:href="#gentle-wave" x="48" y="5" />
          <use xlink:href="#gentle-wave" x="48" y="7" />
        </g>
      </svg>
    </div>
    <main>
      <div class="inner">
        <div id="main" class="pjax">
          
  <div class="article wrap">
    
<div class="breadcrumb" itemscope itemtype="https://schema.org/BreadcrumbList">
<i class="ic i-home"></i>
<span><a href="/blog/">首页</a></span>
</div>

    <article itemscope itemtype="http://schema.org/Article" class="post block" lang="zh-CN">
  <link itemprop="mainEntityOfPage" href="http://fairy77.gitee.io/2020/03/01/linux-basic-operation/">

  <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="image" content="/blog/images/avatar.jpg">
    <meta itemprop="name" content="Rain Bear">
    <meta itemprop="description" content=", ">
  </span>

  <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="Endless">
  </span>

  <div class="body md" itemprop="articleBody">
    

    <p>注：此片命令以 CentOS6 为基准，存在部分 CentOS7 会注明。</p>
<h2 id="1用户"><a class="markdownIt-Anchor" href="#1用户">#</a> 1. 用户</h2>
<p><code>useradd [用户名]</code> <br>
 <code>useradd -d [目录] [用户名]</code></p>
<span id="more"></span>
<p><code>useradd -g [组名] [用户名]</code> <br>
 <code>userdel [用户名]</code> <br>
 <code>userdel -r [用户名]</code> （会删除主目录）<br>
 <code>passwd [用户名]</code> （修改密码）<br>
 <code>usermod -g [组名] [用户名]</code> （修改用户所在组）<br>
 <code>id [用户名]</code> （查看用户信息）</p>
<h2 id="2组"><a class="markdownIt-Anchor" href="#2组">#</a> 2. 组</h2>
<p><code>Groupadd [组名]</code> <br>
 <code>Groupdel [组名]</code></p>
<ul>
<li>/etc/passwd 用户信息</li>
<li>/etc/shadow 密码信息</li>
<li>/etc/group 组信息</li>
</ul>
<h2 id="3运行级别"><a class="markdownIt-Anchor" href="#3运行级别">#</a> 3. 运行级别</h2>
<ul>
<li>位于 /etc/inittab 文件</li>
<li>0123456 代表各个级别</li>
<li><code>init [级别]</code>  修改级别</li>
</ul>
<h2 id="4cd复制"><a class="markdownIt-Anchor" href="#4cd复制">#</a> 4.cd 复制</h2>
<p><code>cp [文件] [地址]</code> <br>
 <code>cp - r [目录] [地址]</code> （递归 拷贝目录下所有）</p>
<h2 id="5添加"><a class="markdownIt-Anchor" href="#5添加">#</a> 5. 添加 &gt;  &gt;&gt;</h2>
<p>添加内容</p>
<h2 id="6head"><a class="markdownIt-Anchor" href="#6head">#</a> 6.Head</h2>
<p><code>head [文件]</code> <br>
 <code>head -n [行数] [文件]</code></p>
<h2 id="7tail"><a class="markdownIt-Anchor" href="#7tail">#</a> 7.Tail</h2>
<p><code>tail [文件]</code> <br>
 <code>tail -n [行数] [文件]</code> <br>
 <code>tail -f [文件]</code> （实时监控）</p>
<h2 id="8ln创建软连接"><a class="markdownIt-Anchor" href="#8ln创建软连接">#</a> 8.Ln 创建软连接</h2>
<p><code>ln -s [原目录] [快捷点]</code> <br>
 <code>ln -s  /root  /home/rootlink</code></p>
<h2 id="9日期类"><a class="markdownIt-Anchor" href="#9日期类">#</a> 9. 日期类</h2>
<p><code>date +%Y...</code> <br>
 <code>date -s 字符串时间</code> （设置时间）<br>
 <code>cal</code></p>
<h2 id="10-查询"><a class="markdownIt-Anchor" href="#10-查询">#</a> 10. 查询</h2>
<p><code>find [搜索范围] -name [文件名]</code> <br>
 <code>find [搜索范围] -user [用户]</code> <br>
 <code>find [搜索范围] -size [大小]</code>  （+20k ,20k,-20k）<br>
 <code>locate</code>  （使用前要 updatedb）</p>
<h2 id="11-grep过滤-和-管道符"><a class="markdownIt-Anchor" href="#11-grep过滤-和-管道符">#</a> 11. Grep（过滤） 和 管道符 |</h2>
<p><code>cat hello.txt | grep -in yes</code>  (n 匹配行号 i 不区分大小写)</p>
<h2 id="12压缩-解压"><a class="markdownIt-Anchor" href="#12压缩-解压">#</a> 12. 压缩 解压</h2>
<ul>
<li>.gz<br>
 <code>gzip [文件]</code> <br>
 <code>gunzip [.gz包]</code></li>
<li>.zip<br>
 <code>gip -r mypackage.zip /home</code> （r 递归压缩，文件夹）<br>
 <code>unzip mypackage.zip -d /opt</code> （d 解压到指定文件夹）</li>
<li>.tar.gz<br>
 <code>tar -zcvf ab.tar.gz a.txt b.txt</code> <br>
 <code>tar -zcvf myhome.tar.gz /home</code> <br>
 <code>tar -zxvf myhome.tar.gz -C /opt</code></li>
</ul>
<h2 id="13-文件权限修改chmod"><a class="markdownIt-Anchor" href="#13-文件权限修改chmod">#</a> 13. 文件权限修改 chmod</h2>
<p><img data-src="linux-basic-operation/%E6%96%87%E4%BB%B6%E6%9D%83%E9%99%90.png" alt=""></p>
<ul>
<li>第一种：（u 用户，g 组，o 其他用户，a 所有，用 +，-，= 便是权限变动）<br>
 <code>chmod u=rwx,g=r,o=r [文件名]</code> <br>
 <code>chmod u-x [文件名]</code> <br>
 <code>chmod g+w [文件名]</code></li>
<li>第二种：r=4,w=2,x=1<br>
 <code>chmod u=rwx,g=rx,o=r [文件名] </code> <br>
相当于:<br>
 <code>chmod 754 [文件名]</code></li>
</ul>
<h2 id="14-修改文件所在组和用户"><a class="markdownIt-Anchor" href="#14-修改文件所在组和用户">#</a> 14. 修改文件所在组和用户</h2>
<p><code>chown [用户] [文件名]</code>  修改文件所有者 chown<br>
 <code>chown [newuser] [文件]</code> <br>
 <code>chown [newuser:newgroup] [文件]</code> （同时修改用户和组）<br>
 <code>chown -R [newuser] [目录]</code> （目录下所有文件全改）<br>
 <code>chgrp [组名] [文件名]</code> （通 chown）</p>
<h2 id="15任务调度crontab"><a class="markdownIt-Anchor" href="#15任务调度crontab">#</a> 15. 任务调度 crontab</h2>
<p><code>crontab -e</code>  编辑<br>
 <code>crontab -l</code>  列出<br>
 <code>crontab -r</code>  删除所有任务调度<br>
 <code>crontab -u</code>  指定用户<br>
 <code>service crond restart</code>  重启任务调度<br>
 <code>*/1 * * * * date &gt;&gt; /tmp/to.txt</code>  每分钟输入时间</p>
<ul>
<li>的含义 1-5：
<ul>
<li>分钟：0-59</li>
<li>小时：0-23</li>
<li>天数：1-31</li>
<li>月数：1-12</li>
<li>星期：0-7（0 和 7 都代表星期日）</li>
</ul>
</li>
<li>特殊符号说明：
<ul>
<li>* 任何时间</li>
<li>，不连续的点</li>
<li>- 范围</li>
<li>*/n 每隔多久执行一次</li>
</ul>
</li>
</ul>
<h2 id="16lsblk-f查看分区情况"><a class="markdownIt-Anchor" href="#16lsblk-f查看分区情况">#</a> 16.Lsblk -f 查看分区情况</h2>
<h2 id="17如何增加一块硬盘"><a class="markdownIt-Anchor" href="#17如何增加一块硬盘">#</a> 17. 如何增加一块硬盘</h2>
<ul>
<li>1）虚拟机添加硬盘</li>
<li>2）分区<br>
 <code>fdisk /dev/sdb</code></li>
<li>3）格式化<br>
 <code>mkfs -t xfs /dev/sdb1</code></li>
<li>4）挂载
<ul>
<li>创建挂载目录  <code>/home/newdisk </code></li>
<li>挂载 mount  <code>/dev/sdb1 /home/newdisk</code></li>
</ul>
</li>
<li>5）设置可以自动挂载 (前四步只是临时挂载，重启就会失效)<br>
vim /etc/fstab<br>
<img data-src="linux-basic-operation/%E8%87%AA%E5%8A%A8%E6%8C%82%E8%BD%BD.png" alt=""></li>
</ul>
<h2 id="18查看磁盘使用情况"><a class="markdownIt-Anchor" href="#18查看磁盘使用情况">#</a> 18. 查看磁盘使用情况</h2>
<p><code>df -h</code>  查看所有磁盘<br>
 <code>du -ach --max-dipth=1</code>  目录<br>
 <code>ll /home | grep &quot;^-&quot; | wc -l</code>  统计目录下文件个数<br>
 <code>ll -R /home | grep &quot;^-&quot; | wc -l</code>  统计目录及其子目录下文件个数<br>
查看树状目录 安装 tree 指令</p>
<h2 id="19配置ip"><a class="markdownIt-Anchor" href="#19配置ip">#</a> 19. 配置 ip</h2>
<p><code>vim /etc/sysconfig/network-scripts/ifcfg-ens33</code> <br>
<img data-src="linux-basic-operation/ip%E9%85%8D%E7%BD%AE.png" alt=""></p>
<h2 id="20进程管理"><a class="markdownIt-Anchor" href="#20进程管理">#</a> 20. 进程管理</h2>
<ul>
<li>查看：<br>
 <code>ps -aux</code> <br>
 <code>Ps -ef</code> <br>
 树状形式：<br>
 <code>pstree -p</code>  显示进程 id<br>
 <code>pstree -u</code>  显示所属用户</li>
<li>杀死：<br>
 <code>kill -9(强制杀死) [进程id]</code> <br>
 <code>killall [指令（gedit）]</code></li>
</ul>
<h2 id="21服务管理service-systemctl"><a class="markdownIt-Anchor" href="#21服务管理service-systemctl">#</a> 21. 服务管理 service systemctl</h2>
<ul>
<li>启动 /… 服务:<br>
 <code>service [服务名] [start/stop/restart/reload/status]</code> <br>
 Centos7 往后:<br>
 <code>systemctl [start/stop/restart/reload/status] [服务名]</code> <br>
 注：这两种是临时的。重启后还是以前的样子。</li>
<li>查看服务：<br>
 <code>setup</code> <br>
 查看 /etc/init.d/ 目录<br>
 CenOs7:<br>
 <code>systemctl -al</code> <br>
 <code>chkconfig (sshd) --list</code></li>
<li>开机是否启动:<br>
 <code>chkconfig sshd --level 5 off </code> 设置好后需要重启才能生效<br>
 Centos7 开机自启动服务:<br>
 <code>systemctl enable nginx.service</code></li>
</ul>
<h2 id="22动态监控进程"><a class="markdownIt-Anchor" href="#22动态监控进程">#</a> 22. 动态监控进程</h2>
<p><code>top -d(设置几秒刷新一次)/-i/-p</code> <br>
 进入监控状态 u 指定用户 k 杀死进程（后面加进程号）P 排序（pid 排序：P,M,N）<br>
netstat 查看网络情况:<br>
 <code>netstat -anp</code>  (an 按一定顺序排列输出 p 显示哪个进程在调用)</p>
<h2 id="23rpm包管理"><a class="markdownIt-Anchor" href="#23rpm包管理">#</a> 23.RPM 包管理</h2>
<ul>
<li>查看：<br>
 <code>rpm -qa | grep xxx</code>  查看已安装的 rpm 列表<br>
 <code>rpm -qa | grep firefox</code> <br>
 <code>rpm -q firefox</code>  查看是否安装<br>
 <code>rpm -qi firefox</code>  查看软件包详情<br>
 <code>rpm -ql firefox </code> 查看软件包安装了哪些文件<br>
 <code>rpm -qf [文件]</code>  查看文件属于哪个包</li>
<li>卸载 rpm 包:<br>
 <code>rpm -e [包名]</code>  rpm -e firefox<br>
 <code>rpm -e -nodeps firefox</code>  有依赖时强制删除</li>
<li>安装 rpm 包:<br>
 <code>rpm -ivh [包名]</code> （i=install v=verbose 提示 h=hash 进度条）<br>
注：首先要挂载镜像，进入里面找到 rpm 包</li>
</ul>
<h2 id="24yum需联网"><a class="markdownIt-Anchor" href="#24yum需联网">#</a> 24.Yum 需联网</h2>
<ul>
<li>查询：<br>
 <code>yum list | grep xxx</code>  软件列表</li>
<li>安装指定的 yum 包：<br>
 <code>yum install xxx</code>  下载安装</li>
</ul>
<h2 id="25javaee"><a class="markdownIt-Anchor" href="#25javaee">#</a> 25.JavaEE</h2>
<h3 id="251-jdk安装"><a class="markdownIt-Anchor" href="#251-jdk安装">#</a> 25.1 jdk 安装</h3>
<p>解压，设置 path</p>
<h3 id="252-tomcat安装"><a class="markdownIt-Anchor" href="#252-tomcat安装">#</a> 25.2 Tomcat 安装</h3>
<p>解压，Startup.sh 启动，开放 8080 防火墙</p>
<p>开放方式：<br>
CentOS 6:<br>
vim /etc/sysconfig/iptables<br>
<img data-src="linux-basic-operation/iptables.png" alt=""></p>
<p>Service iptables restart<br>
CentOS 7 往后：<br>
开放端口： <code>firewall-cmd --permanent --zone=public --add-port=8080/tcp</code> <br>
 关闭端口： <code>firewall-cmd --permanent --zone=public --remove-port=8080/tcp</code> <br>
 查询开放端口： <code>firewall-cmd --list-ports</code> <br>
 重新加载防火墙： <code>firewall-cmd --reload</code></p>
<pre><code>--zone #作用域
--add-port=80/tcp #添加端口，格式为：端口/通讯协议
--permanent #永久生效，没有此参数重启后失效
</code></pre>
<h3 id="253-mysql安装"><a class="markdownIt-Anchor" href="#253-mysql安装">#</a> 25.3 Mysql 安装</h3>
<ul>
<li>删除默认安装<br>
 <code>rpm -qa |grep mysql</code> <br>
 <code>yum remove ...</code></li>
<li>官网下载 MySQL yum 安装源<br>
 <code>wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm</code> <br>
 <code>Rpm -ivh ...</code> <br>
 之后<br>
<img data-src="linux-basic-operation/mysqlRepo.png" alt=""><br>
说明 MySQL yum 仓库添加成功</li>
<li>安装 sql server<br>
 <code>yum install mysql-community-server</code></li>
<li>启动服务<br>
 <code>systemctl start mysqld.service</code></li>
<li>找到生成密码<br>
 <code>cat /var/log/mysqld.log | grep password</code></li>
<li>有密码强度验证<br>
 <code>SHOW VARIABLES LIKE 'validate_password%';</code> <br>
 <code>set global validate_password_policy=0;</code></li>
<li>登录 更改密码</li>
<li>设置远程用户</li>
</ul>
<h2 id="26apt包管理"><a class="markdownIt-Anchor" href="#26apt包管理">#</a> 26.apt 包管理</h2>
<ul>
<li>指令 ：<br>
 <code>sudo apt-get update</code>  更新源<br>
 <code>sudo apt-get install package</code>  安装包<br>
 <code>sudo apt-get remove package</code>  删除包</li>
</ul>
<p><code>sudo apt-cache search package</code>  搜索软件包<br>
 <code>sudo apt-cache show package</code>  获取包的相关信息，汝说明、大小、版本等<br>
 <code>sudo apt-get install package --reinstall</code>  重新安装包</p>
<p><code>sudo apt-get -f install</code>  修复安装<br>
 <code>sudo apt-get remove package --purge</code>  删除包，包括配置文件等<br>
 <code>sudo apt-get build-dep package</code>  安装相关的编译环境</p>
<p><code>sudo apt-get upgrade</code>  更新已安装的包<br>
 <code>sudo apt-get dist-upgrade</code>  升级系统<br>
 <code>sudo apt-cache depends package</code>  了解谁用该包依赖哪些包<br>
 <code>sudo apt-cache rdepends package</code>  查看该包被哪些包依赖<br>
 <code>sudo apt-get source package</code>  下载该包的源代码</p>
<h2 id="27shell编程"><a class="markdownIt-Anchor" href="#27shell编程">#</a> 27.shell 编程</h2>
<p><code>vim myShell.sh</code></p>
<ul>
<li>执行（2 种方式）：
<ul>
<li>1. <code>chmod 744 myShell.sh</code>  赋予权限直接 <code>./myShell.sh</code>  执行</li>
<li>2. <code>sh myShell.sh</code></li>
</ul>
</li>
</ul>
<h3 id="271变量"><a class="markdownIt-Anchor" href="#271变量">#</a> 27.1 变量</h3>
<ul>
<li>语法：
<ul>
<li>1）系统变量 set | more 查看</li>
<li>2）自定义变量 变量 = 值</li>
<li>3）撤销变量 unset 变量</li>
<li>4）静态变量声明 readonly 变量（不能 unset）</li>
<li>5）反引号 <code>...</code>  或者 $(…) 表示值 … 代表命令（ls -l /home)</li>
</ul>
</li>
</ul>
<h3 id="272环境变量"><a class="markdownIt-Anchor" href="#272环境变量">#</a> 27.2 环境变量</h3>
<ul>
<li>
<p>定义变量：<br>
Export 变量名 = 变量值<br>
 TOMCAT_HOME=/opt/tomcat<br>
ExportTOMCAT_HOME</p>
</li>
<li>
<p>立即生效变量<br>
 source 配置文件</p>
<p>单行注释：#<br>
多行注释：&lt;&lt;! … !</p>
</li>
</ul>
<h3 id="273位置参数变量"><a class="markdownIt-Anchor" href="#273位置参数变量">#</a> 27.3 位置参数变量</h3>
<ul>
<li>执行脚本<br>
./myShell.sh 100 200<br>
 说明：100 和 200 就是位置参数，如何在脚本里获取</li>
<li>语法：
<ul>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mtext>（</mtext><mi>n</mi><mtext>是</mtext><mn>0</mn><mo>−</mo><mn>9</mn><mtext>的整数，</mtext><mn>0</mn><mtext>表示命令本身</mtext><mi mathvariant="normal">.</mi><mi mathvariant="normal">/</mi><mi>m</mi><mi>y</mi><mi>S</mi><mi>h</mi><mi>e</mi><mi>l</mi><mi>l</mi><mi mathvariant="normal">.</mi><mi>s</mi><mi>h</mi><mtext>，</mtext><mn>1</mn><mtext>代表</mtext><mn>100</mn><mtext>，</mtext><mn>2</mn><mtext>是</mtext><mn>200</mn><mtext>，十以上</mtext></mrow><annotation encoding="application/x-tex">n（n是0-9的整数，0表示命令本身./myShell.sh，1代表100，2是200，十以上</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.76666em;vertical-align:-0.08333em;"></span><span class="mord mathnormal">n</span><span class="mord cjk_fallback">（</span><span class="mord mathnormal">n</span><span class="mord cjk_fallback">是</span><span class="mord">0</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">9</span><span class="mord cjk_fallback">的</span><span class="mord cjk_fallback">整</span><span class="mord cjk_fallback">数</span><span class="mord cjk_fallback">，</span><span class="mord">0</span><span class="mord cjk_fallback">表</span><span class="mord cjk_fallback">示</span><span class="mord cjk_fallback">命</span><span class="mord cjk_fallback">令</span><span class="mord cjk_fallback">本</span><span class="mord cjk_fallback">身</span><span class="mord">.</span><span class="mord">/</span><span class="mord mathnormal">m</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal" style="margin-right:0.05764em;">S</span><span class="mord mathnormal">h</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord">.</span><span class="mord mathnormal">s</span><span class="mord mathnormal">h</span><span class="mord cjk_fallback">，</span><span class="mord">1</span><span class="mord cjk_fallback">代</span><span class="mord cjk_fallback">表</span><span class="mord">1</span><span class="mord">0</span><span class="mord">0</span><span class="mord cjk_fallback">，</span><span class="mord">2</span><span class="mord cjk_fallback">是</span><span class="mord">2</span><span class="mord">0</span><span class="mord">0</span><span class="mord cjk_fallback">，</span><span class="mord cjk_fallback">十</span><span class="mord cjk_fallback">以</span><span class="mord cjk_fallback">上</span></span></span></span> {10}）</li>
<li>$*（把参数当整体 100 200）</li>
<li>$@（代表所有参数，但是区分对待 100 200）</li>
<li>$#（所有参数个数 2）</li>
</ul>
</li>
</ul>
<h3 id="274预定义变量"><a class="markdownIt-Anchor" href="#274预定义变量">#</a> 27.4 预定义变量</h3>
<p>Shell 设计者实现定义好的变量</p>
<ul>
<li>语法：
<ul>
<li>
<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mtext>当前进程号</mtext><mi>P</mi><mi>I</mi><mi>D</mi></mrow><annotation encoding="application/x-tex"> 当前进程号PID
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord cjk_fallback">当</span><span class="mord cjk_fallback">前</span><span class="mord cjk_fallback">进</span><span class="mord cjk_fallback">程</span><span class="mord cjk_fallback">号</span><span class="mord mathnormal" style="margin-right:0.13889em;">P</span><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="mord mathnormal" style="margin-right:0.02778em;">D</span></span></span></span></span></p>
</li>
<li>$? 最后一次执行命令的返回状态。0 正常执行，非 0 执行不正确</li>
</ul>
</li>
</ul>
<h3 id="275运算符"><a class="markdownIt-Anchor" href="#275运算符">#</a> 27.5 运算符</h3>
<ul>
<li>语法：
<ul>
<li>1）”<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">(</mo><mo stretchy="false">(</mo><mtext>运算式</mtext><mo stretchy="false">)</mo><mo stretchy="false">)</mo><mtext>”或”</mtext></mrow><annotation encoding="application/x-tex">((运算式))”或”</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mopen">(</span><span class="mord cjk_fallback">运</span><span class="mord cjk_fallback">算</span><span class="mord cjk_fallback">式</span><span class="mclose">)</span><span class="mclose">)</span><span class="mord">”</span><span class="mord cjk_fallback">或</span><span class="mord">”</span></span></span></span>[运算式]”<br>
RESULT1=<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">(</mo><mo stretchy="false">(</mo><mo stretchy="false">(</mo><mn>2</mn><mo>+</mo><mn>3</mn><mo stretchy="false">)</mo><mo>∗</mo><mn>4</mn><mo stretchy="false">)</mo><mo stretchy="false">)</mo><mi>R</mi><mi>E</mi><mi>S</mi><mi>U</mi><mi>L</mi><mi>T</mi><mn>2</mn><mo>=</mo></mrow><annotation encoding="application/x-tex">(((2+3)*4))
  RESULT2=</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mopen">(</span><span class="mopen">(</span><span class="mord">2</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">3</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∗</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">4</span><span class="mclose">)</span><span class="mclose">)</span><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="mord mathnormal" style="margin-right:0.05764em;">E</span><span class="mord mathnormal" style="margin-right:0.05764em;">S</span><span class="mord mathnormal" style="margin-right:0.10903em;">U</span><span class="mord mathnormal">L</span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mord">2</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span></span></span></span>[(2+3)*4]</li>
<li>2）Expr m + n（运算符之间要有空格，运算符 +, -, *, /, %）<br>
TEMP= <code>expr 2 + 3</code> <br>
RESULT3= <code>expr $TEMP \* 4</code></li>
</ul>
</li>
</ul>
<h3 id="276条件判断"><a class="markdownIt-Anchor" href="#276条件判断">#</a> 27.6 条件判断</h3>
<ul>
<li>语法：<br>
 <code>[ condition ]</code> <br>
 注：condition 前后有空格，非空返回 true，可使用 $? 验证（0 为 true，&gt;1 为 false）</li>
<li>判断语句：
<ul>
<li>1）两个整数比较<br>
 = 字符串比较<br>
 - lt 小于 - le 小于等于 -eq -gt -ge -ne</li>
<li>2）按照文件权限判断<br>
 - r 有读的权限 -w -x</li>
<li>3）按照文件类型判断<br>
 - f 文件存在且是一个常规文件 -e 文件存在 -d 文件存在并是一个目录</li>
</ul>
</li>
</ul>
<h3 id="277流程控制"><a class="markdownIt-Anchor" href="#277流程控制">#</a> 27.7 流程控制</h3>
<h4 id="2771-分支控制"><a class="markdownIt-Anchor" href="#2771-分支控制">#</a> 27.7.1 分支控制</h4>
<ul>
<li>if 语法：</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">if [ ... ];then</span><br><span class="line">...</span><br><span class="line">fi</span><br></pre></td></tr></table></figure>
<p>或者</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">if [ ... ]</span><br><span class="line">then</span><br><span class="line">...</span><br><span class="line">elif [ ... ]</span><br><span class="line">then</span><br><span class="line">...</span><br><span class="line">fi</span><br></pre></td></tr></table></figure>
<ul>
<li>case 语法：</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">case $变量名 in</span><br><span class="line">“值1”）</span><br><span class="line">...</span><br><span class="line">;;</span><br><span class="line">“值2”)</span><br><span class="line">...</span><br><span class="line">;;</span><br><span class="line">*)</span><br><span class="line">...执行其他</span><br><span class="line">;;</span><br><span class="line">esac</span><br></pre></td></tr></table></figure>
<h4 id="2772-循环控制"><a class="markdownIt-Anchor" href="#2772-循环控制">#</a> 27.7.2 循环控制</h4>
<ul>
<li>for 语法：</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">for 变量 值1 值2 值3...</span><br><span class="line">do</span><br><span class="line">  ...</span><br><span class="line">done</span><br></pre></td></tr></table></figure>
<p>或者：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">for ((初始值;循环条件;变量变化))</span><br><span class="line">do </span><br><span class="line">  ...</span><br><span class="line">done</span><br></pre></td></tr></table></figure>
<ul>
<li>While 语法：</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">while [ ... ]</span><br><span class="line">do </span><br><span class="line">  ...</span><br><span class="line">done</span><br></pre></td></tr></table></figure>
<h3 id="278-读取控制台输入read"><a class="markdownIt-Anchor" href="#278-读取控制台输入read">#</a> 27.8 读取控制台输入 read</h3>
<ul>
<li>语法<br>
 <code>read [选项] [参数]</code></li>
<li>说明
<ul>
<li>选项：<br>
-p：指定读取值时的提示符<br>
 - t：指定读取值时的等待时间（秒），超时就不读取了</li>
<li>变量：指定读取值的变量名</li>
</ul>
</li>
</ul>
<h3 id="279函数"><a class="markdownIt-Anchor" href="#279函数">#</a> 27.9 函数</h3>
<p>系统函数和自定义函数</p>
<ul>
<li>系统函数（介绍两中）：
<ul>
<li>basename 基本语法<br>
返回完整路径最后 / 的部分，常用于获取文件名<br>
 <code>basename [pathname] [suffix]</code> <br>
 <code>basename [string] [suffix]</code> <br>
 suffix 被指定，则会去掉该后缀。</li>
<li>dirname 基本语法<br>
返回完整路径最后 / 的前面部分，常用于返回路劲部分<br>
 <code>dirname [文件绝对路径]</code></li>
</ul>
</li>
<li>自定义函数：
<ul>
<li>语法</li>
</ul>
  <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[ function ] funname[()]</span><br><span class="line">&#123;</span><br><span class="line">    Action;</span><br><span class="line">    [return int]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>说明<br>
调用直接写函数名：funname args1 args2…<br>
 参数调用和位置参数一样</li>
</ul>
</li>
</ul>
<h3 id="2710实用案列数据库备份"><a class="markdownIt-Anchor" href="#2710实用案列数据库备份">#</a> 27.10 实用案列（数据库备份）</h3>
<p><img data-src="linux-basic-operation/%E6%95%B0%E6%8D%AE%E5%BA%93%E5%A4%87%E4%BB%BD.png" alt=""></p>

      <div class="tags">
          <a href="/blog/tags/Linux/" rel="tag"><i class="ic i-tag"></i> Linux</a>
      </div>
  </div>

   <footer>

    <div class="meta">
  <span class="item">
    <span class="icon">
      <i class="ic i-calendar-check"></i>
    </span>
    <span class="text">更新于</span>
    <time title="修改时间：2021-11-28 17:42:10" itemprop="dateModified" datetime="2021-11-28T17:42:10+08:00">2021-11-28</time>
  </span>
  <span id="2020/03/01/linux-basic-operation/" class="item leancloud_visitors" data-flag-title="Linux 基本操作" title="阅读次数">
      <span class="icon">
        <i class="ic i-eye"></i>
      </span>
      <span class="text">阅读次数</span>
      <span class="leancloud-visitors-count"></span>
      <span class="text">次</span>
  </span>
</div>

      
<div class="reward">
  <button><i class="ic i-heartbeat"></i> 赞赏</button>
  <p>请我喝[茶]~(￣▽￣)~*</p>
  <div id="qr">
      
      <div>
        <img data-src="/blog/images/wechatpay.png" alt="Rain Bear 微信支付">
        <p>微信支付</p>
      </div>
      
      <div>
        <img data-src="/blog/images/alipay.png" alt="Rain Bear 支付宝">
        <p>支付宝</p>
      </div>
      
      <div>
        <img data-src="/blog/images/paypal.png" alt="Rain Bear 贝宝">
        <p>贝宝</p>
      </div>
  </div>
</div>

      

<div id="copyright">
<ul>
  <li class="author">
    <strong>Rain Bear： </strong>Rain Bear <i class="ic i-at"><em>@</em></i>Endless
  </li>
  <li class="link">
    <strong>本文链接：</strong>
    <a href="http://fairy77.gitee.io/2020/03/01/linux-basic-operation/" title="Linux 基本操作">http://fairy77.gitee.io/2020/03/01/linux-basic-operation/</a>
  </li>
  <li class="license">
    <strong>版权声明： </strong>本站所有文章除特别声明外，均采用 <span class="exturl" data-url="aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLXNhLzQuMC9kZWVkLnpo"><i class="ic i-creative-commons"><em>(CC)</em></i>BY-NC-SA</span> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

  </footer>

</article>

  </div>
  

<div class="post-nav">
    <div class="item left">
      

  <a href="/blog/2020/03/01/%E9%85%8D%E7%BD%AELinux%E8%99%9A%E6%8B%9F%E6%9C%BA/" itemprop="url" rel="prev" data-background-image="https:&#x2F;&#x2F;tva1.sinaimg.cn&#x2F;mw690&#x2F;6833939bly1giclxxcb6rj20zk0m8b29.jpg" title="配置Linux虚拟机">
  <span class="type">上一篇</span>
  <span class="category"><i class="ic i-flag"></i> </span>
  <h3>配置Linux虚拟机</h3>
  </a>

    </div>
    <div class="item right">
      

  <a href="/blog/2020/03/03/Nginx/" itemprop="url" rel="next" data-background-image="https:&#x2F;&#x2F;tva1.sinaimg.cn&#x2F;mw690&#x2F;6833939bly1giph4fomxoj20zk0m8axp.jpg" title="Nginx学习笔记">
  <span class="type">下一篇</span>
  <span class="category"><i class="ic i-flag"></i> </span>
  <h3>Nginx学习笔记</h3>
  </a>

    </div>
</div>

  
  <div class="wrap" id="comments"></div>


        </div>
        <div id="sidebar">
          

<div class="inner">

  <div class="panels">
    <div class="inner">
      <div class="contents panel pjax" data-title="文章目录">
          <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#1%E7%94%A8%E6%88%B7"><span class="toc-number">1.</span> <span class="toc-text"> 1. 用户</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2%E7%BB%84"><span class="toc-number">2.</span> <span class="toc-text"> 2. 组</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3%E8%BF%90%E8%A1%8C%E7%BA%A7%E5%88%AB"><span class="toc-number">3.</span> <span class="toc-text"> 3. 运行级别</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4cd%E5%A4%8D%E5%88%B6"><span class="toc-number">4.</span> <span class="toc-text"> 4.cd 复制</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5%E6%B7%BB%E5%8A%A0"><span class="toc-number">5.</span> <span class="toc-text"> 5. 添加 &gt;  &gt;&gt;</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6head"><span class="toc-number">6.</span> <span class="toc-text"> 6.Head</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7tail"><span class="toc-number">7.</span> <span class="toc-text"> 7.Tail</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#8ln%E5%88%9B%E5%BB%BA%E8%BD%AF%E8%BF%9E%E6%8E%A5"><span class="toc-number">8.</span> <span class="toc-text"> 8.Ln 创建软连接</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#9%E6%97%A5%E6%9C%9F%E7%B1%BB"><span class="toc-number">9.</span> <span class="toc-text"> 9. 日期类</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#10-%E6%9F%A5%E8%AF%A2"><span class="toc-number">10.</span> <span class="toc-text"> 10. 查询</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#11-grep%E8%BF%87%E6%BB%A4-%E5%92%8C-%E7%AE%A1%E9%81%93%E7%AC%A6"><span class="toc-number">11.</span> <span class="toc-text"> 11. Grep（过滤） 和 管道符 |</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#12%E5%8E%8B%E7%BC%A9-%E8%A7%A3%E5%8E%8B"><span class="toc-number">12.</span> <span class="toc-text"> 12. 压缩 解压</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#13-%E6%96%87%E4%BB%B6%E6%9D%83%E9%99%90%E4%BF%AE%E6%94%B9chmod"><span class="toc-number">13.</span> <span class="toc-text"> 13. 文件权限修改 chmod</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#14-%E4%BF%AE%E6%94%B9%E6%96%87%E4%BB%B6%E6%89%80%E5%9C%A8%E7%BB%84%E5%92%8C%E7%94%A8%E6%88%B7"><span class="toc-number">14.</span> <span class="toc-text"> 14. 修改文件所在组和用户</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#15%E4%BB%BB%E5%8A%A1%E8%B0%83%E5%BA%A6crontab"><span class="toc-number">15.</span> <span class="toc-text"> 15. 任务调度 crontab</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#16lsblk-f%E6%9F%A5%E7%9C%8B%E5%88%86%E5%8C%BA%E6%83%85%E5%86%B5"><span class="toc-number">16.</span> <span class="toc-text"> 16.Lsblk -f 查看分区情况</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#17%E5%A6%82%E4%BD%95%E5%A2%9E%E5%8A%A0%E4%B8%80%E5%9D%97%E7%A1%AC%E7%9B%98"><span class="toc-number">17.</span> <span class="toc-text"> 17. 如何增加一块硬盘</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#18%E6%9F%A5%E7%9C%8B%E7%A3%81%E7%9B%98%E4%BD%BF%E7%94%A8%E6%83%85%E5%86%B5"><span class="toc-number">18.</span> <span class="toc-text"> 18. 查看磁盘使用情况</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#19%E9%85%8D%E7%BD%AEip"><span class="toc-number">19.</span> <span class="toc-text"> 19. 配置 ip</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#20%E8%BF%9B%E7%A8%8B%E7%AE%A1%E7%90%86"><span class="toc-number">20.</span> <span class="toc-text"> 20. 进程管理</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#21%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86service-systemctl"><span class="toc-number">21.</span> <span class="toc-text"> 21. 服务管理 service systemctl</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#22%E5%8A%A8%E6%80%81%E7%9B%91%E6%8E%A7%E8%BF%9B%E7%A8%8B"><span class="toc-number">22.</span> <span class="toc-text"> 22. 动态监控进程</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#23rpm%E5%8C%85%E7%AE%A1%E7%90%86"><span class="toc-number">23.</span> <span class="toc-text"> 23.RPM 包管理</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#24yum%E9%9C%80%E8%81%94%E7%BD%91"><span class="toc-number">24.</span> <span class="toc-text"> 24.Yum 需联网</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#25javaee"><span class="toc-number">25.</span> <span class="toc-text"> 25.JavaEE</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#251-jdk%E5%AE%89%E8%A3%85"><span class="toc-number">25.1.</span> <span class="toc-text"> 25.1 jdk 安装</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#252-tomcat%E5%AE%89%E8%A3%85"><span class="toc-number">25.2.</span> <span class="toc-text"> 25.2 Tomcat 安装</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#253-mysql%E5%AE%89%E8%A3%85"><span class="toc-number">25.3.</span> <span class="toc-text"> 25.3 Mysql 安装</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#26apt%E5%8C%85%E7%AE%A1%E7%90%86"><span class="toc-number">26.</span> <span class="toc-text"> 26.apt 包管理</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#27shell%E7%BC%96%E7%A8%8B"><span class="toc-number">27.</span> <span class="toc-text"> 27.shell 编程</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#271%E5%8F%98%E9%87%8F"><span class="toc-number">27.1.</span> <span class="toc-text"> 27.1 变量</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#272%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F"><span class="toc-number">27.2.</span> <span class="toc-text"> 27.2 环境变量</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#273%E4%BD%8D%E7%BD%AE%E5%8F%82%E6%95%B0%E5%8F%98%E9%87%8F"><span class="toc-number">27.3.</span> <span class="toc-text"> 27.3 位置参数变量</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#274%E9%A2%84%E5%AE%9A%E4%B9%89%E5%8F%98%E9%87%8F"><span class="toc-number">27.4.</span> <span class="toc-text"> 27.4 预定义变量</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#275%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">27.5.</span> <span class="toc-text"> 27.5 运算符</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#276%E6%9D%A1%E4%BB%B6%E5%88%A4%E6%96%AD"><span class="toc-number">27.6.</span> <span class="toc-text"> 27.6 条件判断</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#277%E6%B5%81%E7%A8%8B%E6%8E%A7%E5%88%B6"><span class="toc-number">27.7.</span> <span class="toc-text"> 27.7 流程控制</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#2771-%E5%88%86%E6%94%AF%E6%8E%A7%E5%88%B6"><span class="toc-number">27.7.1.</span> <span class="toc-text"> 27.7.1 分支控制</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2772-%E5%BE%AA%E7%8E%AF%E6%8E%A7%E5%88%B6"><span class="toc-number">27.7.2.</span> <span class="toc-text"> 27.7.2 循环控制</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#278-%E8%AF%BB%E5%8F%96%E6%8E%A7%E5%88%B6%E5%8F%B0%E8%BE%93%E5%85%A5read"><span class="toc-number">27.8.</span> <span class="toc-text"> 27.8 读取控制台输入 read</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#279%E5%87%BD%E6%95%B0"><span class="toc-number">27.9.</span> <span class="toc-text"> 27.9 函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2710%E5%AE%9E%E7%94%A8%E6%A1%88%E5%88%97%E6%95%B0%E6%8D%AE%E5%BA%93%E5%A4%87%E4%BB%BD"><span class="toc-number">27.10.</span> <span class="toc-text"> 27.10 实用案列（数据库备份）</span></a></li></ol></li></ol>
      </div>
      <div class="related panel pjax" data-title="系列文章">
      </div>
      <div class="overview panel" data-title="站点概览">
        <div class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <img class="image" itemprop="image" alt="Rain Bear"
      data-src="/blog/images/avatar.jpg">
  <p class="name" itemprop="name">Rain Bear</p>
  <div class="description" itemprop="description"></div>
</div>

<nav class="state">
    <div class="item posts">
      <a href="/blog/archives/">
        <span class="count">11</span>
        <span class="name">文章</span>
      </a>
    </div>
    <div class="item tags">
      <a href="/blog/tags/">
        <span class="count">8</span>
        <span class="name">标签</span>
      </a>
    </div>
</nav>

<div class="social">
      <span class="exturl item github" data-url="aHR0cHM6Ly9naXRodWIuY29tL2ZhaXJ5Nw==" title="https:&#x2F;&#x2F;github.com&#x2F;fairy7"><i class="ic i-github"></i></span>
      <span class="exturl item zhihu" data-url="aHR0cHM6Ly9naXRlZS5jb20vZmFpcnk3Nw==" title="https:&#x2F;&#x2F;gitee.com&#x2F;fairy77"><i class="ic i-gitee"></i></span>
      <span class="exturl item music" data-url="aHR0cHM6Ly9tdXNpYy4xNjMuY29tLyMvdXNlci9ob21lP2lkPTI1Njk2NTkxNg==" title="https:&#x2F;&#x2F;music.163.com&#x2F;#&#x2F;user&#x2F;home?id&#x3D;256965916"><i class="ic i-cloud-music"></i></span>
</div>

<ul class="menu">
  
    
  <li class="item">
    <a href="/blog/" rel="section"><i class="ic i-home"></i>首页</a>
  </li>

    
  <li class="item">
    <a href="/blog/about/" rel="section"><i class="ic i-user"></i>关于</a>
  </li>

        
  <li class="item dropdown">
      <a href="javascript:void(0);"><i class="ic i-feather"></i>文章</a>
    <ul class="submenu">

        
  <li class="item">
    <a href="/blog/archives/" rel="section"><i class="ic i-list-alt"></i>归档</a>
  </li>

        
  <li class="item">
    <a href="/blog/categories/" rel="section"><i class="ic i-th"></i>分类</a>
  </li>

        
  <li class="item">
    <a href="/blog/tags/" rel="section"><i class="ic i-tags"></i>标签</a>
  </li>

  </ul>
    
  <li class="item">
    <a href="/blog/friends/" rel="section"><i class="ic i-heart"></i>friends</a>
  </li>

    
  <li class="item">
    <a href="/blog/links/" rel="section"><i class="ic i-magic"></i>links</a>
  </li>


</ul>

      </div>
    </div>
  </div>

  <ul id="quick">
    <li class="prev pjax">
        <a href="/blog/2020/03/01/%E9%85%8D%E7%BD%AELinux%E8%99%9A%E6%8B%9F%E6%9C%BA/" rel="prev" title="上一篇"><i class="ic i-chevron-left"></i></a>
    </li>
    <li class="up"><i class="ic i-arrow-up"></i></li>
    <li class="down"><i class="ic i-arrow-down"></i></li>
    <li class="next pjax">
        <a href="/blog/2020/03/03/Nginx/" rel="next" title="下一篇"><i class="ic i-chevron-right"></i></a>
    </li>
    <li class="percent"></li>
  </ul>
</div>


        </div>
        <div class="dimmer"></div>
      </div>
    </main>
    <footer id="footer">
      <div class="inner">
        <div class="widgets">
          
<div class="rpost pjax">
  <h2>随机文章</h2>
  <ul>
      
  <li class="item">
    
<div class="breadcrumb">
</div>

    <span><a href="/blog/2020/03/19/%E6%95%B0%E7%BB%84%E7%9A%84%E4%BD%BF%E7%94%A8/" title="数组的使用">数组的使用</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
</div>

    <span><a href="/blog/2020/02/29/MySQL%E5%AE%89%E8%A3%85/" title="MySQL安装">MySQL安装</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
</div>

    <span><a href="/blog/2020/02/28/%E8%8E%B7%E5%8F%96%E7%94%A8%E9%94%AE%E7%9B%98%E8%BE%93%E5%85%A5%E5%B8%B8%E7%94%A8%E7%9A%84%E4%B8%A4%E7%A7%8D%E6%96%B9%E6%B3%95/" title="获取用键盘输入常用的两种方法">获取用键盘输入常用的两种方法</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
</div>

    <span><a href="/blog/2020/02/28/String%E5%92%8CStringBuffer%E3%80%81StringBuilder%E7%9A%84%E5%8C%BA%E5%88%AB%EF%BC%9F/" title="String和StringBuffer、StringBuilder的区别？">String和StringBuffer、StringBuilder的区别？</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
</div>

    <span><a href="/blog/2021/11/19/tomcat/" title="tomcat">tomcat</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
</div>

    <span><a href="/blog/2020/03/01/%E9%85%8D%E7%BD%AELinux%E8%99%9A%E6%8B%9F%E6%9C%BA/" title="配置Linux虚拟机">配置Linux虚拟机</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
</div>

    <span><a href="/blog/2020/03/08/SpringBoot/" title="SpringBoot学习笔记1">SpringBoot学习笔记1</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
</div>

    <span><a href="/blog/2020/03/03/Nginx/" title="Nginx学习笔记">Nginx学习笔记</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
</div>

    <span><a href="/blog/2020/03/01/linux-basic-operation/" title="Linux基本操作">Linux基本操作</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
</div>

    <span><a href="/blog/2020/03/20/MySQL%E7%B4%A2%E5%BC%95%E5%8E%9F%E7%90%86/" title="MySQL索引原理">MySQL索引原理</a></span>
  </li>

  </ul>
</div>
<div>
  <h2>最新评论</h2>
  <ul class="leancloud-recent-comment"></ul>
</div>

        </div>
        <div class="status">
  <div class="copyright">
    
    &copy; 2019 – 
    <span itemprop="copyrightYear">2021</span>
    <span class="with-love">
      <i class="ic i-sakura rotate"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">Rain Bear @ 夏季大三角</span>
  </div>
  <div class="count">
    <span class="post-meta-item-icon">
      <i class="ic i-chart-area"></i>
    </span>
    <span title="站点总字数">106k 字</span>

    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="ic i-coffee"></i>
    </span>
    <span title="站点阅读时长">1:36</span>
  </div>
  <div class="powered-by">
    基于 <span class="exturl" data-url="aHR0cHM6Ly9oZXhvLmlv">Hexo</span> & Theme.<span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2FtZWhpbWUvaGV4by10aGVtZS1zaG9rYQ==">Shoka</span>
  </div>
</div>

      </div>
    </footer>
  </div>
<script data-config type="text/javascript">
  var LOCAL = {
    path: '2020/03/01/linux-basic-operation/',
    favicon: {
      show: "（●´3｀●）やれやれだぜ",
      hide: "(´Д｀)大変だ！"
    },
    search : {
      placeholder: "文章搜索",
      empty: "关于 「 ${query} 」，什么也没搜到",
      stats: "${time} ms 内找到 ${hits} 条结果"
    },
    valine: true,fancybox: true,
    copyright: '复制成功，转载请遵守 <i class="ic i-creative-commons"></i>BY-NC-SA 协议。',
    ignores : [
      function(uri) {
        return uri.includes('#');
      },
      function(uri) {
        return new RegExp(LOCAL.path+"$").test(uri);
      }
    ]
  };
</script>

<script src="https://cdn.polyfill.io/v2/polyfill.js"></script>

<script src="//cdn.jsdelivr.net/combine/npm/pace-js@1.0.2/pace.min.js,npm/pjax@0.2.8/pjax.min.js,npm/whatwg-fetch@3.4.0/dist/fetch.umd.min.js,npm/animejs@3.2.0/lib/anime.min.js,npm/algoliasearch@4/dist/algoliasearch-lite.umd.js,npm/instantsearch.js@4/dist/instantsearch.production.min.js,npm/lozad@1/dist/lozad.min.js,npm/quicklink@2/dist/quicklink.umd.js"></script>

<script src="/blog/js/app.js?v=0.2.5"></script>




</body>
</html>
